package com.hippoDocker.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName GatewayConfig
 * @Description TODO gateway配置类
 * @Author hippoDocker
 * @Date 2022/6/27 15:13
 **/
@Configuration
public class GatewayConfig {
    /**
     * @Description TODO自定义路由
     * @param routeLocatorBuilder 路由构建器
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        return routes
                .route("path_route1", r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei"))  //说明：访问localhost:9527/guonei地址会转发到http://news.baidu.com/guonei地址
                .route("path_route2",r->r.path("/guoji")
                        .uri("https://news.baidu.com/guoji"))
                .route("path_route3",r->r.path("/gateway")
                        .uri("https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/"))
                .build();
    }
}
